package com.gexiaobao.pigeon.ui.view

import android.text.InputFilter
import android.text.Spanned

/**
 * @Author      : hxw
 * @Date        : 2024/9/10 17:05
 * @Describe    :
 */
class EnglishInputFilter : InputFilter {

    override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int): CharSequence? {
        for (i in start until end) {
            val c = source[i]
            if (!isEnglishCharacter(c)) {
                return ""
            }
        }
        return null
    }

    private fun isEnglishCharacter(c: Char): Boolean {
        return (c in 'a'..'z') || (c in 'A'..'Z')
    }

}